home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_classes.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  12.2 KB  |  360 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. int  classcnt;
  33.  
  34. static APTR classmoretext0,classmoretext1,classmoretext2,classmoretext3,classmoretext4;
  35.  
  36. static APTR ClassPool = NULL;
  37.  
  38. __asm __saveds LONG classlist_cmpaddressfunc (register __a1 struct ClassEntry *ce1, register __a2 struct ClassEntry *ce2)
  39. {
  40.    return (LONG) ce1->cse_adr - (LONG)ce2->cse_adr;
  41. }
  42.  
  43. struct Hook classlist_cmpaddresshook = {
  44.  {NULL, NULL},
  45.  (ULONG (* )())classlist_cmpaddressfunc,
  46.  NULL, NULL
  47. };
  48.  
  49. __asm __saveds LONG classlist_cmpnamefunc (register __a1 struct ClassEntry *ce1, register __a2 struct ClassEntry *ce2) {
  50.    LONG result;
  51.    if (result = strcmpi (ce1->cse_classname, ce2->cse_classname))
  52.       return (result);
  53.    return (1);
  54. }
  55.  
  56. struct Hook classlist_cmpnamehook = {
  57.  {NULL, NULL},
  58.  (ULONG (* )())classlist_cmpnamefunc,
  59.  NULL, NULL
  60. };
  61.  
  62. __asm __saveds LONG classlist_cmpsuperfunc (register __a1 struct ClassEntry *ce1, register __a2 struct ClassEntry *ce2)
  63. {
  64.    return strcmpi (ce1->cse_super, ce2->cse_super);
  65. }
  66.  
  67. struct Hook classlist_cmpsuperhook = {
  68.  {NULL, NULL},
  69.  (ULONG (* )())classlist_cmpsuperfunc,
  70.  NULL, NULL
  71. };
  72.  
  73. __asm __saveds LONG classlist_dspfunc(register __a2 char **array, register __a1 struct ClassEntry *classentry, register __a0 struct Hook *hook)
  74. {
  75.    if (classentry) {
  76.       *array++ = classentry->cse_address;
  77.       *array++ = classentry->cse_objcnt;
  78.       *array++ = classentry->cse_subcnt;
  79.       *array++ = classentry->cse_super;
  80.       *array++ = classentry->cse_dispatch;
  81.       *array   = classentry->cse_classname;
  82.    } else {
  83.       *array++ = ESC "bAddress";
  84.       *array++ = ESC "bObjects";
  85.       *array++ = ESC "bSubclasses";
  86.       *array++ = ESC "bSuperclass";
  87.       *array++ = ESC "bDispatcher";
  88.       *array   = ESC "bName";
  89.    }
  90.    return (0);
  91. }
  92.  
  93. struct Hook classlist_dsphook = {
  94.  {NULL, NULL},
  95.  (ULONG (* )())classlist_dspfunc,
  96.  NULL, NULL
  97. };
  98.  
  99. void FFreeClass (void) {
  100.    MyFreePoolStructs (&ClassPool, classtext, NULL, classlist);
  101. }
  102.  
  103. int GetClass (struct ClassEntry **first) {
  104.    struct   ClassEntry   *classentry,*previous = NULL;
  105.  
  106.    int classcnt = 0;
  107.    *first = 0;
  108.  
  109.    if (!ClassPool) ClassPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  110.  
  111.    if (clientstate) {
  112.       if (SendDaemon ("GetClassList")) {
  113.          while ((classentry = tbAllocPooled(ClassPool, sizeof(struct ClassEntry))) \
  114.            && (ReceiveDecodedEntry ((UBYTE *) classentry, sizeof (struct ClassEntry)))) {
  115.             IsHex (classentry->cse_address, (long *) &classentry->cse_adr);
  116.  
  117.             if (! *first)
  118.                *first = classentry;
  119.             if (previous)
  120.                previous->cse_next = classentry;
  121.  
  122.             classcnt++;
  123.             previous = classentry;
  124.          }
  125.       }
  126.    } else {
  127.       struct IClass *myclass = MakeClass("« Scout Dummy Class »","rootclass",NULL,0,0);
  128.       struct Node *clist;
  129.       struct Hook *disp;
  130.  
  131.       if(myclass) {
  132.          AddClass(myclass);
  133.          Forbid();
  134.             for(clist=(struct Node *)&myclass->cl_Dispatcher.h_MinNode; clist->ln_Pred; clist=clist->ln_Pred);   /* Search the list head */
  135.             for(clist=clist->ln_Succ; clist->ln_Succ; clist=clist->ln_Succ) {
  136.                if(clist==(struct Node *)myclass) continue;         /* Skip own dummy */
  137.                if(classentry = tbAllocPooled(ClassPool, sizeof(struct ClassEntry))) {
  138.  
  139.                   disp = &((struct IClass *)clist)->cl_Dispatcher;
  140.  
  141.                   classentry->cse_adr = (struct IClass *)clist;
  142.                   _sprintf(classentry->cse_address,"$%08lx",clist);
  143.                   // _sprintf(classentry->cse_super,"$%08lx",((struct IClass *)clist)->cl_Super);
  144.                   if (((struct IClass *)clist)->cl_Super) {
  145.                       strncpy(classentry->cse_super,((struct IClass *)clist)->cl_Super->cl_ID,79);
  146.                   } else {
  147.                       strcpy(classentry->cse_super, "<none>");
  148.                   }
  149.                   _sprintf(classentry->cse_dispatch,"$%08lx",(disp->h_SubEntry ? disp->h_SubEntry : disp->h_Entry));
  150.                   strncpy(classentry->cse_classname,((struct IClass *)clist)->cl_ID,79);
  151.                   _sprintf(classentry->cse_objcnt,"%ld ",((struct IClass *)clist)->cl_ObjectCount);
  152.                   _sprintf(classentry->cse_subcnt,"%ld ",((struct IClass *)clist)->cl_SubclassCount);
  153.  
  154.                   if (! *first)
  155.                      *first = classentry;
  156.                   if (previous)
  157.                      previous->cse_next = classentry;
  158.                   classcnt++;
  159.                   previous = classentry;
  160.                }
  161.             }
  162.          Permit();
  163.          FreeClass(myclass);
  164.       }
  165.    }
  166.    return (classcnt);
  167. }
  168.  
  169. void PrintClass (char *filename) {
  170.    int   i=1;
  171.    BPTR  handle;
  172.    struct ClassEntry *entryp = NULL;
  173.  
  174.    handle = HandlePrintStart (filename);
  175.    if ((handle) && (PrintOneLine (handle, "\n  Address  Objects  Subclasses  Superclass             Dispatcher  Name\n\n"))) {
  176.       if (! WI_Class) {
  177.          i = GetClass (&entryp);
  178.       }
  179.       if (i) {
  180.          for (i=0;;i++) {
  181.             if (WI_Class)
  182.                DoMethod (classlist,MUIM_List_GetEntry,i,&entryp);
  183.             if (!entryp) break;
  184.  
  185.             _sprintf (tmpstr2, " %s %7s %11s  %-20s   %s   %-20s\n", entryp->cse_address, entryp->cse_objcnt, entryp->cse_subcnt, entryp->cse_super, entryp->cse_dispatch, entryp->cse_classname);
  186.             if (! (PrintOneLine (handle, tmpstr2)))
  187.                break;
  188.  
  189.             if (! WI_Class)
  190.                entryp = entryp->cse_next;
  191.          }
  192.       }
  193.    }
  194.    HandlePrintStop();
  195. }
  196.  
  197. void ShowClass (void) {
  198.    struct   ClassEntry   *clas;
  199.  
  200.    ApplicationSleep();
  201.    set(classlist,MUIA_List_Quiet,TRUE);
  202.    set(classlist,MUIA_List_CompareHook,classlist_cmphook_ptr);
  203.    set(BT_ClassRemove, MUIA_Disabled, TRUE);
  204.    set(BT_ClassMore, MUIA_Disabled, TRUE);
  205.    FFreeClass();
  206.  
  207.    classcnt = GetClass (&clas);
  208.  
  209.    while (clas) {
  210.       InsertSortedEntry (classlist, (APTR *) &clas);
  211.       clas = clas->cse_next;
  212.    }
  213.  
  214.    SetCountText (classcount, classcnt);
  215.    AwakeApplication();
  216.    set(classlist,MUIA_List_Quiet,FALSE);
  217. }
  218.  
  219. void SendClassList (void) {
  220.    struct   ClassEntry   *clas;
  221.  
  222.    FFreeClass();
  223.    GetClass (&clas);
  224.  
  225.    while (clas) {
  226.       SendEncodedEntry ((UBYTE *) clas, sizeof (struct ClassEntry));
  227.       clas = clas->cse_next;
  228.    }
  229.    FFreeClass();
  230. }
  231.  
  232. void GetClassMore (struct IClass *bc) {
  233.    unsigned char     *title = "CLASS: ";
  234.    struct   WinFree  *ptr;
  235.    BOOL found = FALSE;
  236.    struct IClass *myclass = MakeClass("« Scout Dummy Class »","rootclass",NULL,0,0);
  237.    struct Node *clist;
  238.  
  239.    if(myclass) {
  240.       AddClass(myclass);
  241.       Forbid();
  242.          for(clist=(struct Node *)&myclass->cl_Dispatcher.h_MinNode; clist->ln_Pred; clist=clist->ln_Pred);   /* Search the list head */
  243.          for(clist=clist->ln_Succ; clist->ln_Succ; clist=clist->ln_Succ) {
  244.             if(clist==(struct Node *)myclass) continue;         /* Skip own dummy */
  245.             if(clist==(struct Node *)bc) {
  246.                found = TRUE;
  247.                break;
  248.             }
  249.          }
  250.       Permit();
  251.       FreeClass(myclass);
  252.    }
  253.  
  254.    if (found && (ptr = AllocWinFree())) {
  255.       ptr->wf_Window = (APTR) WindowObject,
  256.       MUIA_HelpNode, ClassesText,
  257.       MUIA_Window_ID, MakeDetailID('.','C','L','S'),
  258.       WindowContents, VGroup,
  259.          Child, ColGroup(2),
  260.             Child, MyLabel2 ("Name:"),
  261.             Child, classmoretext0 = MyTextObject(),
  262.             Child, MyLabel2 ("Super:"),
  263.             Child, classmoretext1 = MyTextObject(),
  264.          End,
  265.          Child, HGroup,
  266.             Child, MyLabel2 ("Address:\nSuper:\nInstOffset:\nInstSize:"),
  267.             Child, classmoretext2 = MyTextObject2(),
  268.             Child, HSpace(0),
  269.             Child, MyLabel2 ("Entry:\nSubEntry:\nData:\nUserData:"),
  270.             Child, classmoretext3 = MyTextObject2(),
  271.             Child, HSpace(0),
  272.             Child, MyLabel2 ("SubClasses:\nObjects:\nFlags:\nReserved:"),
  273.             Child, classmoretext4 = MyTextObject2(),
  274.          End,
  275.       End, End;
  276.  
  277.       if (ptr->wf_Window) {
  278.          MySetContentsHealed (classmoretext0, "%s", bc->cl_ID);
  279.          MySetContentsHealed (classmoretext1, "%s", bc->cl_Super ? bc->cl_Super->cl_ID : (STRPTR)"---");
  280.          MySetContents (classmoretext2, ESC "r$%08lx\n" ESC "r$%08lx\n" ESC "r%ld\n" ESC "r%ld", bc, bc->cl_Super, bc->cl_InstOffset, bc->cl_InstSize);
  281.          MySetContents (classmoretext3, ESC "r$%08lx\n" ESC "r$%08lx\n" ESC "r$%08lx\n" ESC "r$%08lx", bc->cl_Dispatcher.h_Entry, bc->cl_Dispatcher.h_SubEntry, bc->cl_Dispatcher.h_Data, bc->cl_UserData);
  282.          MySetContents (classmoretext4, ESC "r%ld\n" ESC "r%ld\n" ESC "r$%08lx\n" ESC "r$%08lx", bc->cl_SubclassCount, bc->cl_ObjectCount, bc->cl_Flags, bc->cl_Reserved);
  283.  
  284. //*         HandleFlagsButtonPressed (classmoretext4, ptr, "(COMMODITY)", "Flags", bc->mco_Flags, (struct LongFlag *) &bc_flags, NULL, 'b');
  285.          HandleWindowOpen (ptr, title, bc->cl_ID);
  286.          HandleWindowClose (ptr);
  287.       }
  288.    }
  289. }
  290.  
  291.  
  292. APTR ClassSortList[] = {
  293.    &classlist_cmpaddresshook,
  294.    &classlist_cmpnamehook,
  295.    &classlist_cmpsuperhook,
  296.    NULL
  297. };
  298.  
  299. static const char *CYA_ClassSortText[] = {
  300.    "address",
  301.    "name",
  302.    "superclass",
  303.    NULL
  304. };
  305.  
  306. APTR WI_Class, classlist, classtext, classcount, CY_ClassSort;
  307. int  classsortstate = 0;
  308. APTR BT_ClassUpdate, BT_ClassPrint, BT_ClassRemove, BT_ClassMore, BT_ClassExit;
  309.  
  310. char class_title[WINDOWTITLELEN];
  311.  
  312. void ClassWindow (BOOL state) {
  313.    if (state) {
  314.       if (WI_Class) {
  315.          ShowClass();
  316.       } else {
  317.          WI_Class = WindowObject,
  318.          MUIA_Window_Title, MyGetWindowTitle (class_title, "CLASSES"),
  319.          MUIA_HelpNode, ClassesText,
  320.          MUIA_Window_ID, MakeListID('C','L','A','S'),
  321.          WindowContents, VGroup,
  322.             Child, classlist = MyListviewObject ("DELTA=8,DELTA=8 P=\33r,DELTA=8 P=\33r,DELTA=8,DELTA=8,",&classlist_dsphook),
  323.             Child, MyBelowSortedListview (&classtext, &classcount, &CY_ClassSort, CYA_ClassSortText, classsortstate),
  324.             Child, MyVSpace(2),
  325.             Child, VGroup,
  326.                Child, HGroup, MUIA_Group_SameSize, TRUE,
  327.                   Child, BT_ClassUpdate     = KeyButtonA (UpdateText   ,ID_CLASSUPDATE),
  328.                   Child, BT_ClassPrint      = KeyButtonA (PrintText    ,ID_CLASSPRINT),
  329.                   Child, BT_ClassRemove     = KeyButtonA (RemoveText   ,ID_CLASSREMOVE),
  330.                   Child, BT_ClassMore       = KeyButtonA (MoreText     ,ID_CLASSMORE),
  331.                   Child, BT_ClassExit       = KeyButtonA (ExitText     ,ID_CLASSEXIT),
  332.                End,
  333.             End,
  334.          End, End;
  335.  
  336.          if (WI_Class) {
  337.             DoMethod (AP_Scout,OM_ADDMEMBER,WI_Class);
  338.             DoMethod (WI_Class,MUIM_Window_SetCycleChain,classlist,CY_ClassSort,BT_ClassUpdate,BT_ClassPrint,BT_ClassRemove,BT_ClassMore,BT_ClassExit,NULL);
  339.             DoMethod (CY_ClassSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_CLASSSORT);
  340.  
  341.             SetCloseRequest (WI_Class,ID_CLASSEXIT);
  342.             SetListActive (classlist,ID_CLASSLV_ACTIVE);
  343.             SetListviewDoubleClick (classlist,ID_CLASSMORE);
  344.  
  345.             ShowClass();
  346.  
  347.             SetWindowOpen (WI_Class,classlist,ID_CLASSEXIT);
  348.          }
  349.       }
  350.    } else if ((! state) && (WI_Class)) {
  351.       SetWindowClose (WI_Class,TRUE);
  352.       FFreeClass();
  353.       DoMethod (AP_Scout,OM_REMMEMBER,WI_Class);
  354.       MUI_DisposeObject (WI_Class);
  355.       WI_Class = NULL;
  356.       classlist = NULL;
  357.    }
  358. }
  359.  
  360.